package cn.zhz.service.user;

import cn.zhz.dao.user.UserMapper;
import cn.zhz.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;

    @Override
    public boolean checkUserExist(String userCode) {
        return userMapper.getUserByUCode(userCode)!=null;
    }

    @Override
    public User getUserByUCode(String userCode) {
        return userMapper.getUserByUCode(userCode);
    }

    @Override
    public List<User> getUserList(String queryUserName, int queryUserRole,
                                  int currentPageNo, int pageSize) {
        int beginIndex = (currentPageNo-1)*pageSize;
        return userMapper.getUserList(queryUserName, queryUserRole, beginIndex,
                pageSize);
    }


    @Override
    public int getUserCount(String queryUserName, int queryUserRole) {
        int count = 0;

        try {
            count = userMapper.getUserCount(queryUserName,queryUserRole);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return count;
    }

    @Override
    public User loginUser(String userCode, String userPassword) {
        User user=userMapper.getUserByUCode(userCode);

        if(!user.getUserPassword().equals(userPassword)){
            user=null;
        }
        return user;
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public boolean updateUser(User user) {
        Boolean flag=false;
        if(userMapper.updateUser(user)>0){
            flag=true;
        }
        return flag;

    }

    @Override
    public User UserId(int uid) {
        return userMapper.UserId(uid);
    }

    @Override
    public int updatePwd(int id, String pwd) {
        return userMapper.updatePwd(id,pwd);
    }

    @Override
    public int delUser(int uid) {
        return  userMapper.delUser(uid);
    }


}
